package com.eltsistemas.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.eltsistemas.modelo.Funcionario;
import com.eltsistemas.modelo.Usuario;

public class FuncionarioDao_Lista {
	
	private Session session;
	
	public FuncionarioDao_Lista(Session session)
	{
		this.session = session;
	}
	
	public List<Funcionario> listaAll(Usuario usuario)
	{
		List<Funcionario> fList = new ArrayList<>();
		if(usuario.getResponsavel() != null)
		{
			String hql="select f from Funcionario as f WHERE f.setor.responsavel.id=:id_responsavel order by nome asc";
			Query query = this.session.createQuery(hql);
			query.setLong("id_responsavel", usuario.getResponsavel().getId());
			fList = query.list();
		}
		else
		{
			String hql="from Funcionario WHERE id_setor=:id_setor order by nome asc";
			Query query = this.session.createQuery(hql);
			query.setLong("id_setor", usuario.getSetor().getId());
			fList = query.list();
		}
		return fList;
	}

}
